<template>
    <div class="body-container">
        <div class="back-button" @click="goBack">
            <i class="fa fa-arrow-left"></i>
            返回
        </div>
        <div class="title-section">
            <h1 class="main-title">五脏与五行</h1>
            <p class="subtitle">探索中医五行与人体脏腑的奥秘</p>
        </div>
        <div class="content-container">
            <div class="left-section">
                <div class="wuxing-circle">
                    <svg class="circle-frame" width="600" height="600" viewBox="0 0 600 600">
                        <g :style="{ transform: `rotate(${rotationAngle}deg)`, transformOrigin: 'center' }">
                            <circle cx="300" cy="300" r="170" stroke="#fff" stroke-width="2" fill="none" />

                            <!-- 相生关系（顺时针）-->
                            <path d="M300,131 A160,162 0 0 1 465,260" stroke="#FFD700" stroke-width="3" fill="none"
                                marker-end="url(#arrowGold)" class="sheng-path" />
                            <!-- 水生木 -->
                            <path d="M300,131 A160,162 0 0 1 465,260" stroke="#87CEEB" stroke-width="3" fill="none"
                                marker-end="url(#arrowBlue)" class="sheng-path" transform="rotate(72 300 300)" />
                            <!-- 木生火 -->
                            <path d="M300,131 A160,162 0 0 1 465,260" stroke="#4CAF50" stroke-width="3" fill="none"
                                marker-end="url(#arrowGreen)" class="sheng-path" transform="rotate(144 300 300)" />
                            <!-- 火生土 -->
                            <path d="M300,131 A160,162 0 0 1 465,260" stroke="#FF6B6B" stroke-width="3" fill="none"
                                marker-end="url(#arrowRed)" class="sheng-path" transform="rotate(216 300 300)" />
                            <!-- 土生金 -->
                            <path d="M300,131 A160,162 0 0 1 465,260" stroke="#DEB887" stroke-width="3" fill="none"
                                marker-end="url(#arrowBrown)" class="sheng-path" transform="rotate(288 300 300)" />



                        </g>

                        <!-- 箭头定义 -->
                        <defs>
                            <marker id="arrowGreen" markerWidth="13" markerHeight="13" refX="9" refY="3" orient="auto"
                                markerUnits="strokeWidth">
                                <path d="M0,0 L0,6 L9,3 z" fill="#4CAF50" />
                            </marker>
                            <marker id="arrowOrange" markerWidth="13" markerHeight="13" refX="9" refY="3" orient="auto"
                                markerUnits="strokeWidth">
                                <path d="M0,0 L0,6 L9,3 z" fill="#FF5722" />
                            </marker>
                            <marker id="arrowBrown" markerWidth="13" markerHeight="13" refX="9" refY="3" orient="auto"
                                markerUnits="strokeWidth">
                                <path d="M0,0 L0,6 L9,3 z" fill="#795548" />
                            </marker>
                            <marker id="arrowGold" markerWidth="13" markerHeight="13" refX="9" refY="3" orient="auto"
                                markerUnits="strokeWidth">
                                <path d="M0,0 L0,6 L9,3 z" fill="#FFD700" />
                            </marker>
                            <marker id="arrowRed" markerWidth="13" markerHeight="13" refX="9" refY="3" orient="auto"
                                markerUnits="strokeWidth">
                                <path d="M0,0 L0,6 L9,3 z" fill="#FF4444" />
                            </marker>
                            <!-- 添加蓝色箭头定义  -->
                            <marker id="arrowBlue" markerWidth="13" markerHeight="13" refX="9" refY="3" orient="auto"
                                markerUnits="strokeWidth">
                                <path d="M0,0 L0,6 L9,3 z" fill="#87CEEB" />
                            </marker>
                        </defs>
                    </svg>
                    <div class="wuxing-element1" v-for="(element, index) in imgUrls" :key="element.name"
                        :class="element.type" :style="{
                            transform: `rotate(${index * (360 / imgUrls.length) + rotationAngle}deg) translate(280px) rotate(-${index * (360 / wuxingElements.length) + rotationAngle}deg)`
                        }">
                        <div class="image-container">
                            <img :src="element" :alt="element" class="organ-image">
                        </div>
                    </div>
                    <div 
                        class="wuxing-element1" 
                        v-for="(element, index) in wuxingElements" 
                        :key="element.name"
                        :class="element.type"
                        :style="{ 
                            transform: `rotate(${index * (360 / wuxingElements.length) + rotationAngle}deg) translate(230px) rotate(-${index * (360 / wuxingElements.length) + rotationAngle}deg)` 
                        }"
                    >
                    <div class="image-container">
                            <h3>{{ element.organ }}</h3>
                        </div>
                </div>
                    <div class="wuxing-element" v-for="(element, index) in wuxingElements" :key="element.name"
                        :class="element.type" :style="{
                            transform: `rotate(${index * (360 / wuxingElements.length) + rotationAngle}deg) translate(150px) rotate(-${index * (360 / wuxingElements.length) + rotationAngle}deg)`
                        }">
                        <div class="element-content">
                            <h3>{{ element.name }}</h3>
                        </div>
                    </div>
                </div>
            </div>
            <div class="right-section">
                <div class="description-panel">
                    <div class="organ-description" v-for="(element, index) in wuxingElements" :key="element.name">
                        <h3 :class="element.type">{{ element.name }}与{{ element.organ }}</h3>
                        <p>{{ element.description }}</p>
                        <div class="correspondence-info">
                            <div class="constitution-list">
                                <h4>对应体质：</h4>
                                <ul>
                                    <li v-for="constitution in element.constitution" :key="constitution">
                                        {{ constitution }}
                                    </li>
                                </ul>
                            </div>
                            <div class="tea-list">
                                <h4>推荐茶类：</h4>
                                <ul>
                                    <li v-for="tea in element.teaTypes" :key="tea">
                                        {{ tea }}
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'WuXingChart',
    data() {
        return {
            wuxingElements: [
                {
                    name: '金',
                    type: 'metal',
                    organ: '肺',
                    description: '肺主气司呼吸，在五行中属金。金有清肃、收敛的特性，肺具有清肃之性，可将吸入的清气和脾转输的津液、水谷精微向下布散，并清除呼吸道的异物，以保持呼吸道的洁净。',
                    constitution: ['气虚质', '特禀质'],
                    teaTypes: ['白茶', '黄茶']
                },
                {
                    name: '水',
                    type: 'water',
                    organ: '肾',
                    description: '肾藏精，主水液代谢，与水的润下特性相符。肾中所藏之精能滋养全身，肾还能主持和调节人体的水液代谢，使水液代谢平衡。',
                    constitution: ['阳虚质', '阴虚质'],
                    teaTypes: ['黑茶', '红茶']
                },
                {
                    name: '木',
                    type: 'wood',
                    organ: '肝',
                    description: '肝主疏泄，喜条达而恶抑郁，与木的生长舒展特性相似。肝的疏泄功能正常，则气机调畅，气血和调，脏腑功能协调。',
                    constitution: ['气郁质', '血瘀质'],
                    teaTypes: ['绿茶', '花茶']
                },
                {
                    name: '火',
                    type: 'fire',
                    organ: '心',
                    description: '心主血脉，藏神，五行属火。火有温热、光明、向上的特性，心阳具有温煦推动血液运行的作用，使人体保持温暖，精神饱满。',
                    constitution: ['湿热质', '痰湿质'],
                    teaTypes: ['乌龙茶', '红茶']
                },
                {
                    name: '土',
                    type: 'earth',
                    organ: '脾',
                    description: '脾主运化，为气血生化之源，在五行中属土。土有生化、承载、受纳的特性，脾能将饮食水谷转化为精微物质，并将其运输到全身，滋养脏腑经络、四肢百骸。',
                    constitution: ['平和质', '痰湿质'],
                    teaTypes: ['乌龙茶', '黑茶']
                }
            ],
            imgUrls: [
                require('@/assets/肺.png'),
                require('@/assets/肾.png'),
                require('@/assets/肝.png'),
                
                require('@/assets/心.png'),
                require('@/assets/脾.png'),
            ],
            rotationAngle: 0
        }
    },
    mounted() {
        this.startRotation();
    },
    methods: {
        goBack() {
            this.$router.back()
        },
        startRotation() {
            const animate = () => {
                this.rotationAngle = (this.rotationAngle + 0.02) % 360;
                requestAnimationFrame(animate);
            };
            animate();
        }
    }
}
</script>

<style scoped>
.body-container {
    min-height: 100vh;
    padding: 0px;
    background: linear-gradient(135deg, #1a1f2c 0%, #2d3748 100%);
    color: #fff;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.title-section {
    margin-top: 5vh;
    margin-bottom: 50px;
    text-align: center;
}

.main-title {
    font-size: 48px;
    /* 减小字体大小 */
    font-weight: bold;
    margin: 0 0 15px;
    background: linear-gradient(45deg, #f8e8ba, #d09d54);
    /* 金木相生的颜色 */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: titleFadeIn 1s ease-in-out;
    letter-spacing: 2px;
        
  font-family: 'STXingkai', 'Arial', sans-serif;
  letter-spacing: 1px;
}

.subtitle {
    color: rgba(255, 255, 255, 0.9);
    
    font-size: 18px;
    letter-spacing: 1px;
    font-weight: 300;
    
    background: linear-gradient(45deg, #f8e8ba, #d09d54);
    /* 金木相生的颜色 */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.content-container {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    gap: 40px;
    min-height: calc(100vh - 200px);
    /* 减去标题和边距的高度 */
}

.left-section {
    flex: 0 0 800px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.right-section {
    flex: 1;

    max-height: calc(100vh - 200px);
    /* 设置最大高度 */
    position: sticky;
    top: 20px;
}

.description-panel {
    width: 100%;
    height: 100%;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    overflow-y: auto;
    /* 添加垂直滚动 */
    max-height: calc(100vh - 240px);
    /* 留出一些边距 */
}

.wuxing-circle {
    position: relative;
    width: 700px;
    /* 减小宽度以避免溢出 */
    height: 700px;
    /* 保持宽高一致 */
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    /* 居中显示 */
}

/* 自定义滚动条样式 */
.description-panel::-webkit-scrollbar {
    width: 0;
    /* 将宽度设置为0来隐藏滚动条 */
    display: none;
    /* 完全隐藏滚动条 */
}

.description-panel {
    -ms-overflow-style: none;
    /* IE 和 Edge */
    scrollbar-width: none;
    /* Firefox */
    width: 8px;
}

.description-panel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.description-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.description-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* 调整图片容器大小 */
.wuxing-element1 {
    width: 200px;
    /* 稍微减小尺寸 */
    height: 100px;
}

.image-container {
    width: 100%;
    height: 100%;
}

/* 调整圆圈大小 */
.circle-frame {
    width: 600px;
    height: 600px;
}

.description-panel {
    width: 350px;
    /* 从400px减小到350px */
    margin-left: 20px;
    /* 从40px减小到20px */
    padding: 15px;
    /* 从20px减小到15px */
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    overflow-y: auto;
    max-height: calc(100vh - 240px);
    -ms-overflow-style: none;
    /* IE 和 Edge */
    scrollbar-width: none;
    /* Firefox */
}

.organ-description {
    margin-bottom: 20px;
    /* 从30px减小到20px */
    padding: 12px;
    /* 从15px减小到12px */
    border-radius: 8px;
    /* 从10px减小到8px */
    transition: all 0.3s ease;
}

.organ-description h3 {
    font-size: 1.2rem;
    /* 从1.4rem减小到1.2rem */
    margin-bottom: 8px;
    /* 从10px减小到8px */
}

.organ-description p {
    font-size: 0.95rem;
    /* 从1rem减小到0.95rem */
    line-height: 1.5;
    /* 从1.6减小到1.5 */
    color: rgba(255, 255, 255, 0.8);
}

/* 调整五行图的宽度 */
.wuxing-circle {
    width: 700px;
}

.wuxing-circle {
    position: relative;
    width: 800px;
    height: 800px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: -200px;
    /* 从-150px改为-200px，使布局更靠上 */
}

.title-section {
    margin-top: 3vh;
    /* 从5vh减小到3vh */
    margin-bottom: 30px;
    /* 从50px减小到30px */
    text-align: center;
}

.wuxing-element1 {
    /* background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.2) 100%); */
    border-radius: 50%;
    width: 60px;
    /* 从100px减小到60px */
    height: 60px;
    /* 从100px减小到60px */
    padding: 8px;
    /* 从10px减小到8px，保持比例 */
    /* box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); */
    transition: all 0.4s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: absolute;
    will-change: transform;
}

.wuxing-element2 {
    border-radius: 50%;
    width: 60px;
    /* 从100px减小到60px */
    height: 60px;
    /* 从100px减小到60px */
    padding: 8px;
    /* 从10px减小到8px，保持比例 */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.4s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: absolute;
    will-change: transform;
}

.wuxing-element {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.2) 100%);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.4s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: absolute;
    will-change: transform;
}

.wuxing-element:hover {
    transform: scale(1.1) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 2;
}

.element-content h3 {
    font-size: 2rem;
    margin: 0;
}

/* 五行元素的颜色样式 */
.metal {
    border: 4px solid #FFD700;
    color: #FFD700;
}

.wood {
    border: 4px solid #90EE90;
    color: #90EE90;
}

.water {
    border: 4px solid #87CEEB;
    color: #87CEEB;
}

.fire {
    border: 4px solid #FF6B6B;
    color: #FF6B6B;
}

.earth {
    border: 4px solid #DEB887;
    color: #DEB887;
}

.circle-frame {
    position: absolute;
    z-index: 1;
}

.back-button {
    position: fixed;
    top: 20px;
    left: 20px;
    padding: 10px 20px;
    background: linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(0, 255, 255, 0.3) 100%);
    color: #fff;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    z-index: 100;
    font-size: 16px;
}

.back-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

@keyframes titleFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wuxing-element1 {
    background: none;
    border: none;
    width: 80px;
    /* 从120px减小到80px */
    height: 80px;
    /* 保持宽高一致 */
    padding: 0;
    box-shadow: none;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    will-change: transform;
}

.image-container {
    width: 100%;
    /* 保持填满父容器 */
    height: 100%;
    /* 保持填满父容器 */
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    overflow: hidden;
    /* background: rgba(255, 255, 255, 0.1); */
}

.organ-image {
    width: 80%;
    /* 从85%减小到80% */
    height: 80%;
    /* 从85%减小到80% */
    object-fit: contain;
    transition: all 0.3s ease;
    filter: brightness(1.2);
}

.wuxing-element1:hover .organ-image {
    transform: scale(1.1);
    filter: brightness(1.4);
}

/* 添加图例样式 */
.legend {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 10px;
    backdrop-filter: blur(5px);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-line {
    width: 20px;
    height: 2px;
}

.legend-line.sheng {
    background: #4CAF50;
}

.legend-line.ke {
    background: #FF4444;
    border-top: 2px dashed #FF4444;
}

.legend-text {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.9);
}

.circle-frame g {
    transition: transform 0.1s linear;
    transform-origin: center;
}

/* 添加箭头动画效果 */
.sheng-path {
    opacity: 0.8;
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.5));
    transition: all 0.3s ease;
}

.ke-path {
    opacity: 0.6;
    filter: drop-shadow(0 0 2px rgba(255, 0, 0, 0.3));
    transition: all 0.3s ease;
}

.sheng-path:hover,
.ke-path:hover {
    opacity: 1;
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.8));
    stroke-width: 4;
}

/* 修改虚线样式 */
.ke-path {
    stroke-dasharray: 10, 10;
    animation: dashOffset 20s linear infinite;
}

@keyframes dashOffset {
    from {
        stroke-dashoffset: 0;
    }

    to {
        stroke-dashoffset: 200;
    }
}

.correspondence-info {
    margin-top: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.constitution-list, .tea-list {
    margin-bottom: 10px;
}

.constitution-list h4, .tea-list h4 {
    color: #32ccee;
    font-size: 1rem;
    margin-bottom: 5px;
}

.constitution-list ul, .tea-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.constitution-list li, .tea-list li {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    padding: 3px 0;
}

/* 为不同五行添加对应的颜色 */
.metal .correspondence-info {
    border-left: 3px solid #FFD700;
}

.water .correspondence-info {
    border-left: 3px solid #87CEEB;
}

.wood .correspondence-info {
    border-left: 3px solid #90EE90;
}

.fire .correspondence-info {
    border-left: 3px solid #FF6B6B;
}

.earth .correspondence-info {
    border-left: 3px solid #DEB887;
}
</style>